'use strict';

const Subscription = require('egg').Subscription;

class UpdateRecommend extends Subscription {

    static get schedule() {
        return {
            cron: '0 0 12 * * *',
            type: 'worker'
        }
    }

    async subscribe() {
        //执行更新推送消息
        const users = await this.app.model.User.findAll({
            attributes: ['id', 'wxapp_openid']
        });
        users.forEach(u => {
            this.service.wechat.send(u.wxapp_openid)
        })
    }
}

module.exports =  UpdateRecommend;